package com.zlm.tools.validation;


/**
 * {@code }
 *
 * @author zlm
 * @since 2025/5/30
 */
public class LengthValidatorHandler implements ValidatorHandler{

    private int min;
    private int max;

    public LengthValidatorHandler(int min, int max) {
        this.min = min;
        this.max = max;
    }

    @Override
    public void validate(String filed,Object value,  ValidatorContext context){
        if(value instanceof String){
            String valueStr = (String) value;
            if(valueStr.length() < min || valueStr.length() > max){
                context.addError(filed + "长度不能小于" + min + "且不能大于" + max);
            }
        }
    }
}
